﻿using UnityEngine;
using System.Collections;


namespace ESCENARIOS {

	public class Limite : MonoBehaviour {

		//Propiedades
		int ancho;
		string tipoLímite; //[Izquierdo, Derecho];

		//Eventos

		/// <summary>
		/// Eventos the click.
		/// </summary>
		void OnTriggerEnter2D(Collider2D coll)
		{
			Debug.Log("Collide");
			BoxCollider2D colLimite = (BoxCollider2D)coll;
			float ancho = colLimite.size.x * 2;
			float alto = colLimite.size.y * 2;
			float posX = colLimite.center.x - colLimite.size.x * 2;
			float posY = colLimite.center.y - colLimite.size.y * 2;
			Debug.Log("posX = " + posX + ", posY = " + posY + ", ancho = " + ancho + ", alto = " + alto);
			Debug.Log("Juego.MouseClickPosX = " + Juego.MouseClickPosX + ", Juego.MouseClickPosY = " + Juego.MouseClickPosY);
			if(DetectarClick (posX, posY, ancho, alto))
			{
				Debug.Log("Click dentro de limite!");
				int direccion;
				if(this.name == "LimiteDerecho")
					direccion = +1;
				else
					direccion = -1;
			
				new Escena().CambiarPantalla(Escena.PantallaActual, direccion);
			}
		}

		public bool DetectarClick(float pX, float pY, float pAncho, float pAlto)
		{
			Rect rectanguloArea = new Rect(pX, pY, pAncho, pAlto);
			if(rectanguloArea.Contains(new Vector3(Juego.MouseClickPosX, Juego.MouseClickPosY)))
				return true;
			else
				return false;
			
		}
	}	
}